import os
import subprocess
import re

volume_info = subprocess.check_output(["amixer", "-D", "pulse", "get", "Master"])
'''
# you can see the front and right information of volume
# use this to add or sub percent
# amixer -D pulse sset Master 10%+
# 
# use this to close or open audio
# amixer -D pulse sset Master toggle
# 
# use this to set special value
# amixer -D pulse sset Master 50%

'''

def find_percentage_occurrences(input_string):
    # 使用正则表达式查找第一个和第二个[x%]
    matches = re.findall(r'\[\d+%]', input_string)

    # 如果至少找到两个匹配项，则返回第一个和第二个匹配项
    if len(matches) >= 2:
        return matches[0], matches[1]
    else:
        return None, None


# 调用函数查找匹配项
first_match, second_match = find_percentage_occurrences(str(volume_info))

# 打印结果
print("左耳", first_match)
print("右耳", second_match)


# print(volume_info)